<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/10
 * Time: 10:12
 */

namespace app\admin\controller;


use app\admin\model\Comment;

class CommentController extends BaseController
{
    public function index()
    {

        $this->assign([
            'list' => Comment::all(),
        ]);
        return $this->fetch();
    }

    public function reply()

    {
        if($this->request->isPost())
        {
            $data = input('post.');
            $Comment = new Comment;
            $data['reply_time'] = date('Y-m-d H:i:s',time());
            $Comment->allowField(true)->isUpdate(true)->save($data);
            return array('msg' => '回复成功','status' => 1,'icon' => 1);
        }
        $this->assign([
            'info' => Comment::get(input('id/d')),
        ]);
        return $this->fetch();

    }

    public function del()
    {
        Comment::destroy(input('id/d'));
        return array('msg' => '删除成功','status' => 1,'icon' => 1);
    }

    public function change()
    {
        $id = input('id/d');
        $info = Comment::get($id);
        if($info['state'] == 1){
             $info->save(['state' => 0]);
             return array('msg' => '已禁用','status' => 1,'icon' => 1);
        }else{
            $info->save(['state' => 1]);
            return array('msg' => '已启用','status' => 1,'icon' => 1);
        }
    }
}